package com.csgc.camera.widget.dialog

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import com.csgc.camera.constants.Constants.getChangeColor
import com.csgc.camera.util.clickWithTrigger
import com.csgc.camera.widget.dialog.base.BottomDialog
import com.cysd.spsyxj.R
import com.cysd.spsyxj.databinding.DialogImageLabelBinding

class EditImageLabelDialog(val context: Context) {
    private lateinit var mDialog: BottomDialog
    private val mBinding: DialogImageLabelBinding by lazy {
        DialogImageLabelBinding.inflate(LayoutInflater.from(context))
    }
    var listListener: OnLabelCheckListener? = null

    private var selectorColor = 2

    init {
        initDialog()
    }

    private fun initDialog() {
        mDialog = BottomDialog(context).apply {
            //setcontentveiw
            setContentView(mBinding.root)
            findViewById<View>(R.id.siv_label_1)?.clickWithTrigger {
                listListener?.onLabelCheck(1,getChangeColor(context,selectorColor))
            }
            findViewById<View>(R.id.siv_label_2)?.clickWithTrigger {
                listListener?.onLabelCheck(2,getChangeColor(context,selectorColor))
            }
            findViewById<View>(R.id.siv_label_3)?.clickWithTrigger {
                listListener?.onLabelCheck(3,getChangeColor(context,selectorColor))
            }

            mBinding.apply {

                ivClose.clickWithTrigger {
                    dismiss()
                }

                svColor1?.clickWithTrigger { changeColor(1) }
                svColor2?.clickWithTrigger { changeColor(2) }
                svColor3?.clickWithTrigger { changeColor(3) }
                svColor4?.clickWithTrigger { changeColor(4) }
                svColor5?.clickWithTrigger { changeColor(5) }
                svColor6?.clickWithTrigger { changeColor(6) }
                svColor7?.clickWithTrigger { changeColor(7) }
                svColor8?.clickWithTrigger { changeColor(8) }

                svColor2.postDelayed(
                    Runnable {
                        changeColor(2)
                    },
                    500
                )
            }
        }
    }


    private fun changeColor(active: Int) {
        selectorColor = active
        mBinding.apply {
            svColor1?.isSelected = active == 1
            svColor2?.isSelected = active == 2
            svColor3?.isSelected = active == 3
            svColor4?.isSelected = active == 4
            svColor5?.isSelected = active == 5
            svColor6?.isSelected = active == 6
            svColor7?.isSelected = active == 7
        }

    }

    fun show() {
        mDialog.show()
    }


    interface OnLabelCheckListener {
        fun onLabelCheck(style: Int,color:Int)
    }
}